// main.do
// This file replicates the empirical tables and figures in "Leveraging the belief disagreement in climate change: Theory and evidence". It requires propriety data from CoreLogic, First Street Foundation, Gallup, and confidential data from the GSEs stored at the Federal Reserve System's data warehouse (RADAR). These propriety and confidential data sources cannot be shared.
	* Part 1 replicates main Tables 2-5.
	* Part 2 replicates Appendix tables.
	* Part 3 replicates Table 7 and Figure A4 (on GSE loans).
// Inputs: corelogic_slr, gse_fs, gse_fs_time_series
// Outputs: Tables and figures
// Date last updated: 1/27/2025

********************************************************************************	
**				 Set global file paths (change as needed)					  **
********************************************************************************
clear all

// Raw data
	global pathr "YOURPATHHERE\replication\data\raw"
// Intermediate data
	global pathi "YOURPATHHERE\replication\data\intermediate"
// Final data
	global pathf "YOURPATHHERE\replication\data\final"
		
// Data creation code folder
	global pathc "YOURPATHHERE\replication\data_creation_code\sub_do_files"
// Output
	global patho "YOURPATHHERE\replication\output"

********************************************************************************	
**									 MAIN TABLES                              **
********************************************************************************

// Use main dataset
	use "$pathf\corelogic_slr.dta", clear

// TABLE 2: HOUSING PRICE
	eststo p1: reghdfe ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile , cluster(zip_dw) noabsorb
	estadd local controls "Y", replace

	eststo p2: reghdfe ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace

	eststo p3: reghdfe ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population  sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	esttab p1 p2 p3 using "$patho\T2_price.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.above66_buyer) order(1.under 1.under#1.above*) stats(controls fe controlsint N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

// TABLE 3: LEVERAGED
	eststo l1: reghdfe leverage_0 ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile , cluster(zip_dw) noabsorb
	estadd local controls "Y", replace

	eststo l2: reghdfe leverage_0 ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace

	eststo l3: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer c.buyer_income c.buyer_population  sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace

	eststo l4: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population  sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l5: reghdfe leverage_0 ln_sale_price i.SLR##1.above66_buyer i.SLR##c.buyer_income i.SLR##c.buyer_population  sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	esttab l1 l2 l3 l4 l5 using "$patho\T3_lev.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons 0.SLR* *buyer_income* *buyer_pop* 1.above66*) order(1.under 1.under#1.above* 1.SLR 2.SLR 1.SLR#1.above* 2.SLR#1.above*) stats(controls fe controlsint N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "N" "R2"))


// TABLE 4: LONG MATURITY
	eststo m1: reghdfe mtg_30 ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) noabsorb
	estadd local controls "Y", replace

	eststo m2: reghdfe mtg_30 ln_sale_price 1.under buyer_income buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local lenderfe "Y", replace

	eststo m3: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer c.buyer_income c.buyer_population  sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local lenderfe "Y", replace

	eststo m4: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population  sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m5: reghdfe mtg_30 ln_sale_price i.SLR##1.above66_buyer i.SLR##c.buyer_income i.SLR##c.buyer_population  sqft_ptile age_ptile  if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab m1 m2 m3 m4 m5 using "$patho\T4_mat.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons 0.SLR* *buyer_income* *buyer_pop* 1.above66*) order(1.under 1.under#1.above* 1.SLR 2.SLR 1.SLR#1.above* 2.SLR#1.above*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

// TABLE 5: CONFORMING VS NONCONFORMING 

// Gen leveraged-conforming, leveraged-nonconforming, long maturity-conforming, long maturity-nonconforming variables
	gen lc = 0
	replace lc = 1 if leverage_0 == 1 & conforming == 1
	gen lnc = 0
	replace lnc = 1 if leverage_0 == 1 & conforming == 0
	gen mc = 0
	replace mc = 1 if mtg_30 == 1 & conforming == 1
	gen mnc = 0
	replace mnc = 1 if mtg_30 == 1 & conforming == 0

	eststo lc: reghdfe lc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo lnc: reghdfe lnc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo mc: reghdfe mc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo mnc: reghdfe mnc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab lc lnc mc mnc using "$patho\T5_conforming.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.above66* ln_sale_price) order(1.under 1.under#1.above*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

********************************************************************************	
**								 APPENDIX TABLES                              **
********************************************************************************

// TABLE A1: SUM STAT
	gen slr1=(SLR==1)
	label variable slr1 "Moderate SLR Risk"
	gen slr2=(SLR==2)
	label variable slr2 "High SLR Risk"
	label variable mtg_30 "Long Maturity"

	sumstats (sale_price1 leverage_0) (mtg_amt1 mtg_term1 mtg_30 if mtg_amt1>0) (near_dist elevationFS happening_buyer worried_buyer timing_buyer under slr1 slr2) using "$patho\TA01_sumstats.xlsx", stats(mean sd p10 p90 n) replace

// TABLE A2: ROBUSTNESS WITH ALTERNATIVE BELIEF SPECIFICATIONS
	est clear
	* Create quartiles of happening, worry, and belief vars
	foreach var in happening_buyer worried_buyer timing_buyer {
		xtile `var'_quart=`var', nq(4)
		xtile `var'_quint=`var', nq(5)
	}

	* Create dummy for if buyer is from county with belief in top quintile 
	gen happening_top_qrt=(happening_buyer_quart==4)
	gen timing_top_qrt=(timing_buyer_quart==4)
	gen worried_top_qrt=(worried_buyer_quart==4)
	gen happening_top_qnt=(happening_buyer_quint==5)
	gen timing_top_qnt=(timing_buyer_quint==5)
	gen worried_top_qnt=(worried_buyer_quint==5)

// Above median belief regressions
	eststo l1: reghdfe leverage_0  ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l2: reghdfe leverage_0  ln_sale_price 1.under##1.above_worried_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l3: reghdfe leverage_0  ln_sale_price 1.under##1.above_timing_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1: reghdfe mtg_over30  ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m2: reghdfe mtg_over30  ln_sale_price 1.under##1.above_worried_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m3: reghdfe mtg_over30  ln_sale_price 1.under##1.above_timing_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1 l2 l3 m1 m2 m3 using "$patho\TA02_median.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.above66* ln_sale_price 1.under 1.above_worried_buyer 1.above_timing_buyer) order(1.under 1.under#1.above*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

// Quartile belief regressions
	est clear
	eststo l1: reghdfe leverage_0  ln_sale_price 1.under##i.happening_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l2: reghdfe leverage_0  ln_sale_price 1.under##i.worried_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l3: reghdfe leverage_0  ln_sale_price 1.under##i.timing_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1: reghdfe mtg_over30  ln_sale_price 1.under##i.happening_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m2: reghdfe mtg_over30  ln_sale_price 1.under##i.worried_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m3: reghdfe mtg_over30  ln_sale_price 1.under##i.timing_buyer_quart 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1 l2 l3 m1 m2 m3 using "$patho\TA02_quartile.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* ln_sale_price 1.under 4.happening_buyer_quart 4.worried_buyer_quart 4.timing_buyer_quart 2.happening_buyer_quart 2.worried_buyer_quart 2.timing_buyer_quart 3.happening_buyer_quart 3.worried_buyer_quart 3.timing_buyer_quart 1.under#1.happening_buyer_quart 1.under#1.worried_buyer_quart 1.under#1.timing_buyer_quart 1.happening_buyer_quart 1.worried_buyer_quart 1.timing_buyer_quart) order(1.under 1.under#2.happening* 1.under#2.worried* 1.under#2.timing* 1.under#3.happening* 1.under#3.worried* 1.under#3.timing* 1.under#4.happening* 1.under#4.worried* 1.under#4.timing*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))
	est clear

// Continuous belief regressions
	eststo l1: reghdfe leverage_0  ln_sale_price 1.under##c.happening_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l2: reghdfe leverage_0  ln_sale_price 1.under##c.worried_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo l3: reghdfe leverage_0  ln_sale_price 1.under##c.timing_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1: reghdfe mtg_over30  ln_sale_price 1.under##c.happening_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag==0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m2: reghdfe mtg_over30  ln_sale_price 1.under##c.worried_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag==0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo m3: reghdfe mtg_over30  ln_sale_price 1.under##c.timing_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag==0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1 l2 l3 m1 m2 m3 using "$patho\TA02_continuous.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* happening* ln_sale_price 1.under worried* timing*) order(1.under 1.under#c.happening* 1.under#c.worried* 1.under#c.timing*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))
	est clear

// TABLE A3: ROBUSTNESS WITH COUNTY BELIEF VARIABLES BASED ON GALLUP SURVEY DATA
	
	* Make dummies for above median belief variables by year
	bys year: egen median_when = median(imputed_gw_when)
	gen abovewhen_buyer = imputed_gw_when>=median_when
	replace abovewhen_buyer = . if imputed_gw_when == .
	bys year: egen median_worry = median(imputed_gw_worry)
	gen aboveworry_buyer = imputed_gw_worry>=median_worry
	replace aboveworry_buyer = . if imputed_gw_worry == .

	eststo l1_imp: reghdfe leverage_0 ln_sale_price 1.under##1.abovewhen_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1_imp: reghdfe mtg_30 ln_sale_price 1.under##1.abovewhen_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1_imp m1_imp using "$patho\TA03_Gallup.csv",  replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.abovewhen* ln_sale_price) order(1.under 1.under#1.above*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

// TABLE A4: ROBUSTNESS WITH ADDITIONAL COUNTY CONTROLS
	eststo c1: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population 1.under##c.unemp_rate 1.under##c.mean_test_score 1.under##c.total_arrests 1.under##c.bldgs_all 1.under##c.prev_floods 1.under##c.share_minority 1.under##c.share_child 1.under##c.pop_share_age_65plus 1.under##c.pop_share_female sqft_ptile age_ptile, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local new "Y", replace
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo c2: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population 1.under##c.unemp_rate 1.under##c.mean_test_score 1.under##c.total_arrests 1.under##c.bldgs_all 1.under##c.prev_floods 1.under##c.share_minority 1.under##c.share_child 1.under##c.pop_share_age_65plus 1.under##c.pop_share_female sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local new "Y", replace
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab c1 c2 using "$patho\TA04_morecontrols.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) title("Table 1") drop(*ptile* 1.under#c.buyer_income 1.under#c.buyer_population *unemp_rate* *mean_test_score* *total_arrests* *bldgs_all* *prev_floods* *share_minority* *share_child* *pop_share_age_65plus* *pop_share_female* 1.above66_buyer buyer_income buyer_population ln_sale_price _cons) order(1.under 1.under#1.above*) stats(new controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label("Additional Controls" "Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2"))

// TABLE A5: ROBUSTNESS WITH ADDITIONAL POLITICAL AFFILIATION CONTROLS
	* GOP voting share
	eststo lgop: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile 1.under##c.gopshare, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local pol "Republican", replace

	eststo mgop: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile 1.under##c.gopshare if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace
	estadd local pol "Republican", replace

	* Democrat voting share
	eststo ldem: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile 1.under##c.demshare, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local pol "Democrat", replace

	eststo mdem: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile 1.under##c.demshare if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace
	estadd local pol "Democrat", replace

	esttab lgop mgop ldem mdem using "$patho\TA05_political.csv",  replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.above66_buyer gopshare 1.under#c.gopshare demshare 1.under#c.demshare ln_sale_price) order(1.under 1.under#1.above*) stats(controls fe controlsint lenderfe pol N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "Political Control" "N" "R2"))

// TABLE A6: PLACEBO TEST ON BELIEFS
	eststo lp: reghdfe leverage_0 ln_sale_price 1.above66_buyer c.buyer_income c.buyer_population  sqft_ptile age_ptile if under==0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace

	eststo mp: reghdfe mtg_30 ln_sale_price 1.above66_buyer c.buyer_income c.buyer_population  sqft_ptile age_ptile if flag == 0 & under ==0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local lenderfe "Y", replace

	esttab lp mp using "$patho\TA06_placebo.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.above66_buyer) order(*under* *above*)  stats(controls fe lenderfe N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "N" "R2"))

// TABLE A7: ROBUSTNESS WITH BELIEF DUMMY IMPUTED FROM TRANSACTION DATA
	* Get error terms
	reghdfe ln_sale_price 1.under 1.under##c.buyer_income 1.under##c.buyer_population 1.under##c.share_bachelors5 1.under##c.pop_share_age_18_29 1.under##c.pop_share_white sqft_ptile age_ptile , vce(robust) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth) resid
	predict err, residuals
	gen lambdahat = -err

	* Generate pessimistic dummy
	sum lambdahat if under==1, d
	gen pessbuyer = 1 if under == 1 & lambda >= r(p50)
	replace pessbuyer = 0 if under == 1 & lambda < r(p50)
	replace pessbuyer = 0 if under == 0

	eststo l1_lambda: reghdfe leverage_0 ln_sale_price 1.under#1.pessbuyer 1.under##c.buyer_income 1.under##c.buyer_population 1.under##c.share_bachelors5 1.under##c.pop_share_age_18_29 1.under##c.pop_share_white sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1_lambda: reghdfe mtg_30 ln_sale_price 1.under#1.pessbuyer 1.under##c.buyer_income 1.under##c.buyer_population 1.under##c.share_bachelors5 1.under##c.pop_share_age_18_29 1.under##c.pop_share_white sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1_lambda m1_lambda using "$patho\TA07_lambda.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* *share* 1.under#c.buyer_income 1.under#c.buyer_population ln_sale_price buyer_income buyer_population _cons) order(1.under 1.under#1.pessbuyer) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

// TABLE A8: BELIEF CORRELATIONS
	* Create county level lambdahat
	bysort buyer_fips: egen mean_lambda=mean(lambdahat)
	sum mean_lambda, det
	gen above_med_lambda=(mean_lambda>=r(p50))

	* Create above median dummy variables
	gen above_med_imp_when = imputed_gw_when>=median_when
	replace above_med_imp_when = . if imputed_gw_when == .
	gen above_med_imp_worry = imputed_gw_worry>=median_worry
	replace above_med_imp_worry = . if imputed_gw_worry == .
	bys year: egen median_happen = median(happening_buyer)
	gen above_med_happen = happening_buyer>=median_happen
	replace above_med_happen = . if happening_buyer == .
	bys year: egen median_worried = median(worried_buyer)
	gen above_med_worried = worried_buyer>=median_worried
	replace above_med_worried = . if worried_buyer == .
	bys year: egen median_timing = median(timing_buyer)
	gen above_med_timing = timing_buyer>=median_timing
	replace above_med_timing = . if timing_buyer == .

	* Correlation between pess buyer and above med belief variables
	pwcorr above_med_happen above_med_worried above_med_timing above_med_imp_when above_med_imp_worry pessbuyer above_med_lambda, sig

	* Collect table elements, reformat, and export
	collect clear
	collect get corr=vech(r(C)) sig=vech(r(sig))
	collect layout (rowname#result) (roweq)
	collect stars sig 0.01 "***" 0.05 "**" 0.1 "*", attach(corr) shownote
	collect style cell result[corr], maximum(0.99999, label("1")) nformat(%6.4f) halign(center)
	collect style cell result[sig], sformat((%s)) nformat(%6.4f) halign(center)
	collect style header result, level(hide)
	collect style cell border_block[corner row-header], border(right, pattern(nil))
	collect title "Table A8"
	collect export "$patho\TA08_corr.xlsx", replace


// TABLE A9: ROBUSTNESS WITH FEMA FLOOD ZONES
	gen fema_high_buyer=fema_zone*above66_buyer

	eststo f1: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile fema_zone fema_high_buyer, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo f2: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile fema_zone fema_high_buyer if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab f1 f2 using "$patho\TA09_fema.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.under 1.under#1.above66_buyer fema_zone fema_high_buyer) order(*under* *above*)  stats(controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2"))

// TABLE A10: ROBUSTNESS WITH MORE REFINED MEASURES OF SLR RISK
	eststo r1: reghdfe leverage_0 ln_sale_price i.SLR3##1.above66_buyer i.SLR3##c.buyer_income i.SLR3##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo r2: reghdfe mtg_30 ln_sale_price i.SLR3##1.above66_buyer i.SLR3##c.buyer_income i.SLR3##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab r1 r2 using "$patho\TA10_refinedslr.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) title("Table 1") drop(*ptile* *population* *income* 0.SLR3* 1.above66_buyer _cons ln_sale_price) order(*SLR3* *above*) stats(controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2"))

// TABLE A11: ROBUSTNESS WITH ALTERNATIVE FIXED EFFECTS
	* Leveraged
	eststo fe_l1: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B", replace
	estadd local controlsint "Y", replace

	eststo fe_l2: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearqtr)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ Q", replace
	estadd local controlsint "Y", replace

	eststo fe_l3: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearqtr#OO)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ Q $\times$ O", replace
	estadd local controlsint "Y", replace

	eststo fe_l4: reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile , cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth#OO)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ M $\times$ O", replace
	estadd local controlsint "Y", replace

	* Long maturity
	eststo fe_m1: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed lender_code)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo fe_m2: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearqtr lender_code)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ Q", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo fe_m3: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearqtr#OO lender_code)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ Q $\times$ O", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo fe_m4: reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth#OO lender_code)
	estadd local controls "Y", replace
	estadd local fe "Z $\times$ D $\times$ E $\times$ B $\times$ M $\times$ O", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab fe_l1 fe_l2 fe_l3 fe_l4 fe_m1 fe_m2 fe_m3 fe_m4 using "$patho\TA11_fe.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.under 1.under#1.above*)  stats(controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Fixed effects" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2"))

// TABLE A12: ROBUSTNESS WITH NO HOUSING PRICE CONTROL
	eststo l1_price: reghdfe leverage_0 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo m1_price: reghdfe mtg_30 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab l1_price m1_price using "$patho\TA12_noprice.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) title("Table 1") drop(*ptile* *population* *income* 1.above66_buyer _cons) order(*under* *above*) stats(controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2"))

// TABLE A13: RESULTS OVER TIME
	* Dummy for sale before or after 2010
	gen after2010=(year>=2010)
	replace after2010=. if year==.
	
// Loop over before and after 2010 for price, leverage, mortgage regressions
	forval year = 0(1)1 {
		eststo p`year': reghdfe ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if after2010 == `year', cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
		estadd local year "`year'"
		estadd local controls "Y", replace
		estadd local fe "Y", replace
		estadd local controlsint "Y", replace
	}

	forval year = 0(1)1 {
		eststo l`year': reghdfe leverage_0 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if after2010 == `year', cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
		estadd local year "`year'"
		estadd local controls "Y", replace
		estadd local fe "Y", replace
		estadd local controlsint "Y", replace
	}

	forval year = 0(1)1 {
		eststo m`year': reghdfe mtg_30 ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag == 0 &  after2010 == `year', cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
		estadd local year "`year'"
		estadd local controls "Y", replace
		estadd local fe "Y", replace
		estadd local controlsint "Y", replace
		estadd local lenderfe "Y", replace
	}

	esttab p0 p1 l0 l1 m0 m1 using "$patho\TA13_time.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.under 1.under#1.above66_buyer) order(*under* *above*)  stats(year controls fe controlsint lenderfe N r2,  fmt(0 0 0 0 3) label(">= 2010" "Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "N" "R2")

// TABLE A14: OTHER INTENSIVE MARGINS
	* Make variables for log mortgage amount, loan-to-value ratio, mtg interest rate
	gen log_mtg = log(mtg)
	gen ltv=mtg/sale_price1
	gen intr = mtg_int_rate1

	eststo i1: reghdfe log_mtg ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if lev > 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo i2: reghdfe ltv ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if lev > 0, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo i3: reghdfe intr ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code mtg_term)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace
	estadd local yr30 "Y", replace

	esttab i1 i2 i3 using "$patho\TA14_intensive.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(1.under 1.under#1.above66_buyer) order(*under* *above*)  stats(controls fe controlsint lenderfe yr30 N r2,  fmt(0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Buyer County Controls $\times$ SLR" "Lender fe" "30 year fe" "N" "R2"))

// TABLE A15: ROBUSTNESS OF CONFORMING LOAN RESULTS FOR >=2009 SAMPLE
	eststo lc9: reghdfe lc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if year>=2009, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo lnc9: reghdfe lnc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if year>=2009, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace

	eststo mc9: reghdfe mc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag==0 & year>=2009, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	eststo mnc9: reghdfe mnc ln_sale_price 1.under##1.above66_buyer 1.under##c.buyer_income 1.under##c.buyer_population sqft_ptile age_ptile if flag==0 & year>=2009, cluster(zip_dw) absorb(i.zip_dw#i.bin_dist_mi#elev_bin2m#bed#sale_yearmonth lender_code)
	estadd local controls "Y", replace
	estadd local fe "Y", replace
	estadd local controlsint "Y", replace
	estadd local lenderfe "Y", replace

	esttab lc9 lnc9 mc9 mnc9 using "$patho\T15_conforming2009.csv", replace b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(*ptile* _cons *buyer_income* *buyer_pop* 1.above66* ln_sale_price) order(1.under 1.under#1.above*) stats(controls fe lenderfe controlsint N r2,  fmt(0 0 0 0 0 3) label("Property \& Buyer County Controls" "Z $\times$ D $\times$ E $\times$ B $\times$ M fe" "Lender fe" "Buyer County Controls $\times$ SLR" "N" "R2"))

********************************************************************************	
**									GSE CLEANING              	              **
********************************************************************************
// Load confidential data (not included in replication)
	use "$pathf\gse_fs.dta", clear
	drop filename*

// Make variables based on the date
	gen close_year = floor(close_dt/100)
	gen maturity_year = close_year + loan_term/12
	gen close_month = close_dt - 100 * close_year

// Dummy for delinquency if max loan stat is not 0
	gen delinquent = (max_loan_stat!="0")

// Variables for different rates and amounts
	gen monthly_rate = int_rate_orig / 1200
	gen monthly_payment = (loan_amt_orig * monthly_rate)/(1-(1+monthly_rate)^(-loan_term_orig))
	gen payments_made = (2023 - close_year)*12 - close_month + 1
	gen balance_Jan2023 = loan_amt_orig * (1+monthly_rate)^payments_made ///
		- (monthly_payment*((1+monthly_rate)^payments_made-1)/monthly_rate)
	replace balance_Jan2023 = 0 if payments_made>=loan_term_orig
	replace balance_Jan2023 = loan_amt_orig if payments_made <= 0

// Zip code is at high flood risk if average flood risk (from FS) >=2, high risk if >=3
	gen at_risk = flood_zip_avg >= 2 
	gen at_high_risk = flood_zip_avg>=3

********************************************************************************	
**								GSE TABLE 7 & FIG A4                          **
********************************************************************************	
// Table 7
	* Column 1
	count if maturity_year>=2023
	local total_N_2023 = r(N)/10^6
	sum balance_Jan2023 if ~delinquent 
	local total_bal = r(N)*r(mean)/10^12

	* Column 2 
	count if at_risk & maturity_year>=2023
	local at_risk_N_2023 = r(N)/10^6
	sum balance_Jan2023 if at_risk & ~delinquent
	local at_risk_bal = r(N)*r(mean)/10^12

	* Column 3
	count if at_high_risk & maturity_year>=2023
	local at_high_risk_N_2023 = r(N)/10^6
	sum balance_Jan2023 if at_high_risk & ~delinquent
	local at_high_risk_bal = r(N)*r(mean)/10^12

// Put results in matrix and export
	matrix results = (`total_N_2023',`at_risk_N_2023'/`total_N_2023'*100,`at_high_risk_N_2023'/`total_N_2023'*100 \ `total_bal',`at_risk_bal'/`total_bal'*100,`at_high_risk_bal'/`total_bal'*100)
	matrix rownames results = "Number of outstanding loans""Total outstanding balances"
	matrix colnames results = "Total sample" "% at risk" "% at higher risk"
	esttab matrix(results) using "$patho\T7_GSE.csv", replace nonumber noobs label

	
// FIGURE A4: EVENT STUDY 
// Load reshaped confidential data (not included in replication)
	use "$pathf\gse_fs_time_series.dta" , clear

// FL zip codes affected by Hurricane Irma (See Online Appendix B3)
	keep if prop_state == "FL"
	gen byte treated = 0
	replace treated = 1 if inlist(prop_zip,336,314,327,341,338,331,330,320,328,337,349,342,326,339,321,333,334,346,347,335,322,329,344) 

// DiD with treatment group as most affected zip3 in 2017q3
	gen did = treated*post
	xtdidregress (def) (did) if prop_state == "FL", group(loanID) time(t)

// Testing parallel trend assumption
	estat ptrends, verbose

// Generate Figure A4
	estat trendplots 
	graph export "$patho\fig_A4.png", replace